<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="12">
            <a-form-model-item label="开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="beginDate">
              <a-date-picker :disabled="formDisabled" placeholder="请选择开始时间" valueFormat="YYYY-MM-DD" @change="handleChange" v-model="model.beginDate" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="endDate">
              <a-date-picker
                :disabled="formDisabled"
                :disabled-date="disabledDate"
                :default-picker-value="this.model.beginDate"
                placeholder="请选择结束时间"
                valueFormat="YYYY-MM-DD"
                v-model="model.endDate"
                style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="12">
            <a-form-model-item label="教育单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="institution">
              <a-input :disabled="formDisabled" v-model="model.institution" placeholder="请输入教育单位"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="12">
            <a-form-model-item label="学校名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="graduatedFrom">
              <a-input :disabled="formDisabled" v-model="model.graduatedFrom" placeholder="请输入学校名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="专业" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="major">
              <a-input :disabled="formDisabled" v-model="model.major" placeholder="请输入专业"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="获奖情况" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="prizeRecord">
              <a-input :disabled="formDisabled" v-model="model.prizeRecord" placeholder="请输入获奖情况"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import moment from 'moment';

  export default {
    name: 'ErpHrApplyEducationForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 },
        },
        confirmLoading: false,
        validatorRules: {
          beginDate: [{ required: true, message: '请选择开始时间', trigger: 'change' }],
          endDate: [{ required: true, message: '请选择结束时间', trigger: 'change' }],
          institution: [{ required: true, message: '请输入教育单位', trigger: 'blur' }],
          //major: [{ required: true, message: '请输入专业', trigger: 'blur' }],
          graduatedFrom: [{ required: true, message: '请输入学校名称', trigger: 'blur' }],
        },
        url: {
          add: "/api/erp/hr/apply/erpHrApplyEducation/add",
          edit: "/api/erp/hr/apply/erpHrApplyEducation/edit",
          queryById: "/api/erp/hr/apply/erpHrApplyEducation/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      moment,
      handleChange(value) {
        if (this.model.endDate) {
          if ((this.model.endDate).diff((this.model.beginDate), 'days') < 0) {
            this.model.endDate = this.model.beginDate
          }
        }
      },
      disabledDate(current) {
        return current < moment(this.model.beginDate).subtract('day')
      },
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        console.log(this.model);
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            // that.confirmLoading = true;
            // let httpurl = '';
            // let method = '';
            // if(!this.model.id){
            //   httpurl+=this.url.add;
            //   method = 'post';
            // }else{
            //   httpurl+=this.url.edit;
            //    method = 'put';
            // }
            // httpAction(httpurl,this.model,method).then((res)=>{
            //   if(res.success){
            //     that.$message.success(res.message);
            //     that.$emit('ok');
            //   }else{
            //     that.$message.warning(res.message);
            //   }
            // }).finally(() => {
            //   that.confirmLoading = false;
            // })
            that.$emit('ok',that.model);
          }

        })
      },
    }
  }
</script>
